/**
 * @format
 * @Author: TC
 * @Date: 2023-10-23 18:57:06
 * @Last Modified by: TC
 * @Last Modified time: 2025-06-08 12:27:27
 */

import { app } from "../App";
import { CmdItem } from "../Module/InputCmd/CmdItem";

/**
 * 输入命令管理
 */
export class InputCmdManager {
    private _mapInputCmd: Map<number, CmdItem> = null;
    private _bOpen: boolean = false;

    public open(): void {
        if (this._bOpen) {
            return;
        }
        this._bOpen = true;
        this._mapInputCmd = new Map();
        app.tickMgr.add(this);
    }

    /**
     * 添加输入单位
     * @param item
     */
    public add(item: CmdItem): void {
        if (!this._bOpen) {
            return;
        }
        this._mapInputCmd.set(item.entity.uid, item);
    }

    /**
     * 删除输入单位
     * @param uid
     */
    public remove(uid: number): void {
        if (this._mapInputCmd.has(uid)) {
            this._mapInputCmd.delete(uid);
        }
    }

    /**
     * 执行输入命令
     * @param dt
     */
    public tick(dt: number): void {
        this._mapInputCmd.forEach((ic) => {
            ic.execute();
        });
    }
}
